﻿using System.Windows.Input;
using Catel.Messaging;
using Shell.Library.Models;
using Shell.Library.Services;
using System;
using System.Windows;
using Microsoft.Expression.Interactivity.Core;

namespace Interview
{
    /// <summary>
    /// Browser module.
    /// </summary>
    public class ComplainWorkModule : Shell.Library.Modules.ModuleBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ComplainWorkModule"/> class. 
        /// </summary>
        public ComplainWorkModule()
            : base(ModuleConstants.Name)
        {
        }

        protected override void OnInitializing()
        {
            base.OnInitializing();

            //Container.RegisterType(typeof(IInterviewContext), typeof(InterviewContext));
            //Container.RegisterType(typeof(ISessionService), typeof(SessionService));
        }

        /// <summary>
        /// Called when the module has been initialized.
        /// </summary>
        protected override void OnInitialized()
        {
            var shellService = GetService<IShellService>();
            //var goalsViewModel = new GoalsViewModel(shellService);
            //shellService.ShowToolBoxItem<GoalsViewModel>(goalsViewModel, "Goals");
        }

        /// <summary>
        /// Initializes the ribbon.
        /// <para />
        /// Use this method to hook up views to ribbon items.
        /// </summary>
        /// <param name="ribbonService">The ribbon service.</param>
        protected override void InitializeRibbon(IRibbonService ribbonService)
        {
            LoadResourceDictionary();

            ICommand investigateCommand = new ActionCommand(o => GetService<IMessageMediator>().SendMessageAsync(Messages.Investigate));

            // View specific
            //ribbonService.RegisterContextualRibbonItem<InterViewView>(new RibbonButton(ModuleConstants.Name, ModuleConstants.Name, "Investigate", investigateCommand) { ItemImage = "/Interview;component/Resources/Images/Investigate.png" }, ModuleName);

            // Find the template to show as dynamic content. TODO: Refactor, make more elegant.
            var template = Application.Current.Resources["SearchTemplate"] as DataTemplate;
            //ribbonService.RegisterContextualRibbonItem<InterViewView>(new RibbonContentControl(ModuleConstants.Name, "Search") { ContentTemplate = template, Layout = new RibbonItemLayout { Width = 120 } }, ModuleName);
        }

        private void LoadResourceDictionary()
        {
            Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("/ComplainWork;component/ResourceDictionary.xaml", UriKind.RelativeOrAbsolute) });
        }
    }
}